<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
        <canvas width="600" height="400"></canvas>
        <script>
            var myCanvas = document.querySelector("canvas");
            var ctx = myCanvas.getContext("2d");
    
            // 创建渐变方案
            // createLinearGradient(x0,y0,x,y) 渐变长度+方向
            var LineGradient = ctx.createLinearGradient(100,100,300,100);
            LineGradient.addColorStop(0,"pink");
            LineGradient.addColorStop(0.5,"yellow");
            LineGradient.addColorStop(1,"skyblue");
            ctx.fillStyle = LineGradient;
            ctx.fillRect(100,100,200,200);
            
        </script>
    
</body>
</html>